#!/bin/bash
# echo the call so we can see what's going on
echo "$0 $1 $2 $3 $4 $5 $6"

# Check syntax
if [ "$1" = "" ]; then
	echo "$0 called without phase number!"
	exit 0
fi

if [ "$2" = "" ]; then
	echo "$0 called without new value!"
	exit 0
fi

grep NHST `cat GSAS_EXP`.EXP | tail -c67 | head -c65 | sed "s/ //g" > temp.txt
histograms=`cat temp.txt`

# change the phase in all histograms
echo "k l o s" > temp.txt
while [ $histograms -gt 0 ]; do
	echo "p $1" >> temp.txt
	echo "c $2" >> temp.txt
	echo "n" >> temp.txt
	let histograms--
done
echo "x" >> temp.txt
echo "x" >> temp.txt
echo "x" >> temp.txt
echo "x" >> temp.txt

expedt `cat GSAS_EXP` < temp.txt > out.txt

echo "Changed scale value for phase $1 to $2.\newline" >> temp.tex
